package com.scfire.util;

import java.io.IOException;
import java.net.MalformedURLException;

import net.sf.json.JSONObject;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;


public class Test {

    private static final String targetURL = "http://localhost:8080/scfire/pay";
    @SuppressWarnings({ "resource", "deprecation" })
    public static void main(String[] args) {

             try {

            	 JSONObject jsonObj = new JSONObject();
            	 jsonObj.put("customer", "aaaa");
            	 jsonObj.put("apikey", "zzzzz");
            	 // Create the POST object and add the parameters
            	 HttpPost httpPost = new HttpPost(targetURL);
				StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
            	 entity.setContentType("application/json");
            	 httpPost.setEntity(entity);
				HttpClient client = new DefaultHttpClient();
            	 HttpResponse response = client.execute(httpPost);
            	 System.out.println(response);
            	 if (response.getStatusLine().getStatusCode() == 200) {
                     System.out.println("true");
                     String strResult = EntityUtils.toString(response.getEntity());  
                     JSONObject jo = JSONObject.fromObject(strResult);  
                     System.out.println(jo);
                 }
             } catch (MalformedURLException e) {
                  e.printStackTrace();
             } catch (IOException e) {
                  e.printStackTrace();

             }

           }
}
